package com.example.natatorium_management.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.natatorium_management.entity.Good;
import com.example.natatorium_management.entity.Order;
import com.example.natatorium_management.entity.Reserve;
import com.example.natatorium_management.mapper.OrderGoodMapper;
import com.example.natatorium_management.mapper.OrderMapper;
import com.example.natatorium_management.result.restful.R;
import com.example.natatorium_management.result.restful.ResponseEunm;
import com.example.natatorium_management.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {
    @Autowired
    OrderMapper orderMapper;

    @Autowired
    OrderGoodMapper orderGoodMapper;

    @Override
    public R<IPage<Order>> queryPage(int current, int size) {
        return new R<>(ResponseEunm.SUCCESS,orderMapper.queryPage(Page.of(current, size)));
    }

    @Override
    public R<Order> addOrder(Order order) {
        if (orderMapper.addOrder(order)==1){
            return new R<>(ResponseEunm.SUCCESS,null);
        }
        return new R<>(ResponseEunm.ADD_FAIL,null);
    }

    @Override
    public R<Order> deleteOrderById(Integer orderId) {
        if(removeById(orderId)){
            return new R<>(ResponseEunm.SUCCESS,null);
        }
        return new R<>(ResponseEunm.DELETE_FAIL,null);
    }

    @Override
    public R<Order> updateOrder(Order order) {
        if(orderMapper.updateOrder(order)==1){
            return new R<>(ResponseEunm.SUCCESS,null);
        }
        return new R<>(ResponseEunm.UPDATE_FAIL,null);
    }

    @Override
    public R<IPage<Order>> findOrder(Order order,int current,int size) {
        if (order.getPhone() != null) {
           return new R<>(ResponseEunm.SUCCESS,orderMapper.findOrderByPhone(Page.of(current,size),order.getPhone()));
        }
        if (order.getCustomerName()!= null){
            return new R<>(ResponseEunm.SUCCESS,orderMapper.findOrderByCustomerName(Page.of(current,size),order.getCustomerName()));
        }
        return new R<>(ResponseEunm.SUCCESS,orderMapper.findOrderByMemberName(Page.of(current,size),order.getMemberName()));
    }



}
